#define PORT_MCU 10001
#define BUF_SIZE 512
#define MCU_IP "192.168.0.100" 
#define PS_IP "192.168.0.109"  


int main() {

	int sockfd_mcu;
	struct sockaddr_out server_addr_mcu;
	char buffer_mcu[BUF_SIZE];
	//int received_len;


	// 创建UDP套接字
	if ((sockfd_mcu = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("创建套接字失败");
		exit(EXIT_FAILURE);
	};
	// 配置服务器地址

	memset(&server_addr_mcu, 0, sizeof(server_addr_mcu));
	server_addr_mcu.sin_family = AF_INET;
	server_addr_mcu.sin_port = htons(PORT_MCU);

	// 将IP地址转换为网络字节序
	if (inet_pton(AF_INET, MCU_IP, &server_addr_mcu.sin_addr) <= 0) {
		perror("无效的IP地址");
		close(sockfd_mcu);
		exit(EXIT_FAILURE);
	}
	// 要发送的消息
	strcpy(buffer_ps, "readout");


	if (sendto(sockfd_mcu, buffer_mcu, strlen(buffer_mcu), 0,
		(struct sockaddr*)&server_addr_mcu, sizeof(server_addr_mcu)) < 0) {
		perror("发送消息失败");
		close(sockfd_mcu);
		exit(EXIT_FAILURE);
	}
	else {
		printf("消息已发送到 %s:%d\n", ip_addresses_mcu, PORT_MCU);
	}

}